<?php
//管理员设置
class AdminAction extends CommonAction
{
	function index()
	{
	}
	//管理员列表
	public function adminlist()
	{
		 $admin=D('Admin');
		 //print_r($_SESSION);
		 //引入分页类	 
		 import('ORG.Util.Page');
		 $filter['username']=isset($_GET['username'])?$_GET['username']:"";
		 //$list=$admin->filed(pe_admin.id)->select();
		 if(!empty($filter['username']))
		 {
		 	$where['account']=array("like","%admin%");
		 }
		 
		 $list=$admin->where($where)->select();
		 $count=count($list);
		 $page=new Page($count,3,2);
		 $list=$admin->getAdminList($page,$filter);
		 $this->setPageStyle($page);
		 $show=$page->show();
		
		 $this->assign('fpage',$show);
		 $this->assign('list',$list);
		 $this->display();
	}
	
	//添加管理员界面
	public function adminAdd()
   {
		 $role=M('Role');
		 $role_info=$role->field('id,name')->select();
		 $this->assign('role',$role_info);
		 $this->display();
   }
	//保存管理员信息	
	public function save()
	{
		$admin=D('Admin');
		if(!$admin->create())
		{
      		$this->error($admin->getError());
		}
		 else
		{
			if($admin->add())
	  	{
	  		$this->admin_log("添加用户");
		  	$this->assign('jumpUrl','__URL__/adminlist');
      		$this->success("添加成功");
	  	}
			else
		 	{
		 		$this->success("添加失败");
		 	}
    
  }

	}
	
	//编辑管理员信息界面
	public function edit()
   {
		$admin=D('Admin');
		$admin_id=$_GET['id'];
		$admin_info=$admin->getAdminInfo($admin_id);
        $role_info=$admin->getRoleInfo();
    
    //print_r($admin_info);
    
    	$this->assign('role_info',$role_info);
    	$this->assign('admin_info',$admin_info);
		$this->display();
	}
	
	//更新管理员信息	
	public function update()
	{
	   $admin=D('Admin');	
	   $admin_id=$_GET['id'];
	   if(!$admin->create($_POST,2))
	   {
	  	 $this->error($admin->getError());
	   }
	   else
	   {
	   	//import 表单中必须包含一个主键的隐藏区域
	   	  if($admin->save())
	   	  {
	   	  	 $this->admin_log("修改用户");
	   	 	 $this->assign('jumpUrl','__URL__/adminlist');
         	 $this->success("修改成功");
          }
          else
         {
       		 $this->error("修改失败");
         }
    
	   }
	}
	
	//操作日志
	public function log()
	{
		import('ORG.Util.Page');
		$log=new Model("admin_log");
		$log_info=$log->field("pe_admin_log.id as lid,admin_id,controller,action,add_time,desc,account")->join("pe_admin on pe_admin_log.admin_id=pe_admin.id ")->select();
		$count=count($log_info);
		$page=new Page($count,3,2);
		
		$log_info=$log->field("pe_admin_log.id as lid,admin_id,controller,action,add_time,desc,account")->join("pe_admin on pe_admin_log.admin_id=pe_admin.id ")->limit($page->getLimit())->select();
		$show=$page->show();
		$this->assign('fpage',$show);
		$this->assign('log_info',$log_info);
		$this->display();
	}
	
}

?>